package com.guohe3.just.controller;

import com.guohe3.just.common.constants.Constants;
import com.guohe3.just.common.resp.ApiResult;
import com.guohe3.just.common.utils.RestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 浦希成
 * 2019-01-01
 */
@RestController
@RequestMapping("config")
@Api(value = "系统配置", description = "jwc.just.edu.cn/xxxnxl/list.htm")
public class ConfigController {
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("getWeekNum")
    @ApiOperation("查看当前周数")
    public ApiResult getWeekNum() {
        return RestUtil.success("查询成功", redisTemplate.opsForValue().get(Constants.XIAOLI_KEY));
    }

    @GetMapping("addWeekNum")
    @ApiOperation("自增周数")
    public ApiResult addWeekNum() {
        return RestUtil.success("weekNum自增1", redisTemplate.opsForValue().increment(Constants.XIAOLI_KEY, 1L));
    }

    @GetMapping("changeWeekNum/{num}")
    @ApiOperation("改变周数")
    public ApiResult changeWeekNum(@PathVariable Long num) {
        redisTemplate.opsForValue().set(Constants.XIAOLI_KEY, num + "");
        return RestUtil.success("改变周数", "");
    }
}
